/*
 * Copyright 2014 Alex Curran
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.espian.showcaseview.sample;

import com.github.amlcurran.showcaseview.LocalHiLog;
import com.github.amlcurran.showcaseview.ShowcaseView;
import com.github.amlcurran.showcaseview.targets.ViewTarget;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.text.Font;
import ohos.agp.text.TextForm;
import ohos.agp.utils.Color;

import java.io.File;

/**
 * 自定义引导层的标题和描述内容的样式
 */
public class CustomTextAbility extends Ability {
    ShowcaseView showcaseView;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);

        ComponentContainer componentContainer = (ComponentContainer) LayoutScatter.getInstance(this)
                .parse(ResourceTable.Layout_ability_custom_text, null, false);
        setUIContent(componentContainer);
        TextForm textForm = new TextForm();
        TextForm titleTextForm = new TextForm();
        try {
            textForm.setStrikethrough(true);
            textForm.setTextColor(Color.RED.getValue());
            textForm.setTextSize((int) getResourceManager().getElement(ResourceTable.Float_text_size).getFloat());
            textForm.setTextFont(new Font.Builder(new File("resources/rawfile/RobotoSlab-Regular.ttf")).build());
            titleTextForm.setUnderline(true);
            titleTextForm.setTextColor(Color.YELLOW.getValue());
            titleTextForm.setTextSize((int) getResourceManager().getElement(ResourceTable.Float_title_size).getFloat());
            titleTextForm.setTextFont(new Font.Builder(new File("resources/rawfile/RobotoSlab-Regular.ttf")).build());
        } catch (Exception e) {
            LocalHiLog.warn("ShowcaseView", "title or text size not found");
        }
        showcaseView = new ShowcaseView.Builder(this, (ComponentContainer) componentContainer.getComponentParent())
                .withNewStyleShowcase()
                .setTarget(new ViewTarget(ResourceTable.Id_imageView2, this))
                .setContentTextForm(textForm)
                .setContentTitle(ResourceTable.String_custom_text_painting_title)
                .setContentText(ResourceTable.String_custom_text_painting_text)
                .setContentTitlTextForm(titleTextForm)
                .build();
        showcaseView.setTitleTextAlignment(ShowcaseView.TextAlignment.CENTER);
        showcaseView.setDetailTextAlignment(ShowcaseView.TextAlignment.CENTER);
        showcaseView.forceTextPosition(ShowcaseView.BELOW_SHOWCASE);
    }


    @Override
    protected void onStop() {
        super.onStop();
        showcaseView.destory();
    }
}
